import $store from '@/store/index.js';
export default {
	/* 获取群列表 */
	getGroupList() {
		return $store.state.user.sqlite.groups.where({ field: 'mygroup', val: `'1'` }).get()
	},
	//获取群信息
	getGroupInfo(group_id,fields) {
		return $store.state.user.sqlite.groups.where({ field: 'group_id', val: `'${group_id}'` }).fields(fields).first()
	},
	//更新或添加群信息
	async addOrEditGroupInfo(data) {
		//逻辑是先插入如果插入失败，就更新
		try{
			await $store.state.user.sqlite.groups.create(data)
			return true
		}catch(e){
			try{
				await this.editGroupInfo(data.group_id,data)
				return true
			}catch(e){
				console.log(e);
				throw e
			}
		}
	},
	//更新群信息
	editGroupInfo(group_id,data) {
		return $store.state.user.sqlite.groups.where({ field: 'group_id', val: `'${group_id}'`}).update(data)
	},
	//删除群信息
	delGroupInfo(group_id) {
		return $store.state.user.sqlite.groups.where({ field: 'group_id', val: `'${group_id}'`}).delete()
	},
}